//导入http模块
const http = require("http");
// 创建服务器
const server = http.createServer();
//绑定request事件，监听客户端事件
server.on("request", (req, res) => {
  let content = "<h1>404 not found!</h1>";
  if (req.url === "/" || req.url === "/index.html") {
    content = "<h1>This page is index</h1>";
  } else if (req.url === "/about.html") {
    content = "<h1>This page is about</h1>";
  }
  res.setHeader("Content-Type", "text/html;charset=utf-8");
  res.end(content);
});
// 启动服务器
server.listen(80, () => {
  console.log("server running at http://127.0.0.1");
});
